package com.wanbang.sale.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wanbang.sale.commonutils.StringToDateConverter;
import com.wanbang.sale.entity.Aixs;
import com.wanbang.sale.entity.aixsVo.AixsPage;
import com.wanbang.sale.entity.aixsVo.SaleQuery;
import com.wanbang.sale.mapper.AixsMapper;
import com.wanbang.sale.service.AixsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-10-29
 */
@Service
public class AixsServiceImpl extends ServiceImpl<AixsMapper, Aixs> implements AixsService {

    @Autowired
    private StringToDateConverter stringToDateConverter;

    @Autowired
    private AixsMapper aixsMapper;

    @Override
    public AixsPage pageQuery2(Long current, Long size, SaleQuery saleQuery) {

        String salesman = saleQuery.getSalesman();
        String medicine = saleQuery.getMedicine();
        String dept = saleQuery.getDept();
        String begin = saleQuery.getBegin();
        String end = saleQuery.getEnd();

        // 开始页
        long beginPage = (current - 1) *  size + 1;

        // 结束页

//        List<Aixs> aixsList = aixsMapper.pageQuery(current,size);


        return null;
    }

    @Override
    public void pageQuery(Page<Aixs> pageParam, SaleQuery saleQuery) {
        QueryWrapper<Aixs> queryWrapper = new QueryWrapper<>();
//        queryWrapper.orderByDesc("原单审核日期");

        if (saleQuery == null) {
//            baseMapper.selectPage(pageParam, queryWrapper);
            return;
        }

        String dept = saleQuery.getDept();
        String salesman = saleQuery.getSalesman();
        String medicine = saleQuery.getMedicine();
        Date begin = stringToDateConverter.convert(saleQuery.getBegin());
        Date end = stringToDateConverter.convert(saleQuery.getEnd());



        if (!StringUtils.isEmpty(dept)) {
            queryWrapper.like("部门", dept);
        }

        if (!StringUtils.isEmpty(salesman)) {
            queryWrapper.like("业务员", salesman);
        }

        if (!StringUtils.isEmpty(medicine)) {
            queryWrapper.like("药品名称", medicine);
        }

        if (!StringUtils.isEmpty(begin)) {
            queryWrapper.ge("原单审核日期", begin);
        }

        if (!StringUtils.isEmpty(end)) {
            queryWrapper.le("原单审核日期", end);
        }

        baseMapper.selectPage(pageParam, queryWrapper);
    }

}
